package cn.wolfcode.luowowo.mgrsite.controller;

import cn.wolfcode.luowowo.article.domain.Region;
import cn.wolfcode.luowowo.article.service.IDestinationService;
import cn.wolfcode.luowowo.article.service.IRegionService;
import cn.wolfcode.luowowo.common.query.QueryObject;
import cn.wolfcode.luowowo.common.util.AjaxResult;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/region")
public class RegionController {
    @Reference
    private IRegionService regionService;

    @Reference
    private IDestinationService destinationService;

    @RequestMapping("/list")
    public String list(@ModelAttribute("qo") QueryObject qo, Model model) {
        model.addAttribute("pageInfo", regionService.query(qo));
        return "region/list";
    }

    @RequestMapping("/listDests")
    @ResponseBody
    public Object listDests() {
        //[{id:xx,name:xx},{id:xx,name:xx},...]
        return destinationService.list();
    }

    @RequestMapping("/listDestByRegionId")
    @ResponseBody
    public Object listDestByRegionId(Long rid) {
        //[{name:xx},{name:xx},...]
        return destinationService.listByReginId(rid);
    }

    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(Region entity) {
        regionService.saveOrUpdate(entity);
        return new AjaxResult();
    }
}
